//
//  HHContextMenuSample.swift
//  HHSwiftuiPractice
//
//  Created by YL-Hong on 2023/10/8.
// ContextMenu 长按 弹出快捷菜单

import SwiftUI

struct HHContextMenuSample: View {
    
    private let menuItems = ContextMenu {
           Button {
               // Add this item to a list of favorites.
           } label: {
               Label("Add to Favorites", systemImage: "heart")
           }
           Button {
               // Open Maps and center it on this item.
           } label: {
               Label("Show in Maps", systemImage: "mappin")
           }
       }
       
       @State var showContextMenu: Bool = true
    
    var body: some View {
       
        VStack(alignment: .leading, spacing: 10.0) {
                   Image(systemName: "house.fill")
                   Text("SwiftUI sample")
                       .font(.title2)
                   Text("How to use context menu")
                       .font(.subheadline)
               }
               .padding()
               .foregroundColor(Color.white)
               .background(Color.green)
               .cornerRadius(20)
               .contextMenu(showContextMenu ? menuItems : nil)
               
           }


}

struct HHContextMenuSample_Previews: PreviewProvider {
    static var previews: some View {
        HHContextMenuSample()
    }
}
